<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Rescue</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Rescue</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/rescue_rb.html">
                vendor/rails/actionpack/lib/action_controller/rescue.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Actions that fail to perform as expected throw exceptions. These exceptions
can either be rescued for the public view (with a nice user-friendly
explanation) or for the developers view (with tons of debugging
information). The developers view is already implemented by the Action
Controller, but the public view should be tailored to your specific
application.
</p>
<p>
The default behavior for public exceptions is to render a static html file
with the name of the error code thrown. If no such file exists, an empty
response is sent with the correct status code.
</p>
<p>
You can override what constitutes a local request by overriding the <tt><a
href="Rescue.html#M000859">local_request?</a></tt> method in your own
controller. Custom rescue behavior is achieved by overriding the <tt><a
href="Rescue.html#M000857">rescue_action_in_public</a></tt> and <tt><a
href="Rescue.html#M000860">rescue_action_locally</a></tt> methods.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000859">local_request?</a>&nbsp;&nbsp;
      <a href="#M000856">log_error</a>&nbsp;&nbsp;
      <a href="#M000858">render_optional_error_file</a>&nbsp;&nbsp;
      <a href="#M000855">rescue_action</a>&nbsp;&nbsp;
      <a href="#M000857">rescue_action_in_public</a>&nbsp;&nbsp;
      <a href="#M000860">rescue_action_locally</a>&nbsp;&nbsp;
      <a href="#M000861">rescue_action_without_handler</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Rescue/ClassMethods.html" class="link">ActionController::Rescue::ClassMethods</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">LOCALHOST</td>
          <td>=</td>
          <td class="context-item-value">'127.0.0.1'.freeze</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_RESCUE_RESPONSE</td>
          <td>=</td>
          <td class="context-item-value">:internal_server_error</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_RESCUE_RESPONSES</td>
          <td>=</td>
          <td class="context-item-value">{       'ActionController::RoutingError'             =&gt; :not_found,       'ActionController::UnknownAction'            =&gt; :not_found,       'ActiveRecord::RecordNotFound'               =&gt; :not_found,       'ActiveRecord::StaleObjectError'             =&gt; :conflict,       'ActiveRecord::RecordInvalid'                =&gt; :unprocessable_entity,       'ActiveRecord::RecordNotSaved'               =&gt; :unprocessable_entity,       'ActionController::MethodNotAllowed'         =&gt; :method_not_allowed,       'ActionController::NotImplemented'           =&gt; :not_implemented,       'ActionController::InvalidAuthenticityToken' =&gt; :unprocessable_entity</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_RESCUE_TEMPLATE</td>
          <td>=</td>
          <td class="context-item-value">'diagnostics'</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_RESCUE_TEMPLATES</td>
          <td>=</td>
          <td class="context-item-value">{       'ActionView::MissingTemplate'       =&gt; 'missing_template',       'ActionController::RoutingError'    =&gt; 'routing_error',       'ActionController::UnknownAction'   =&gt; 'unknown_action',       'ActionView::TemplateError'         =&gt; 'template_error'</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000859" class="method-detail">
        <a name="M000859"></a>

        <div class="method-heading">
          <a href="#M000859" class="method-signature">
          <span class="method-name">local_request?</span><span class="method-args">(</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
True if the request came from localhost, 127.0.0.1. Override this method if
you wish to redefine the meaning of a local request to include remote IP
addresses or other criteria.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000859-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000859-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 102</span>
102:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">local_request?</span> <span class="ruby-comment cmt">#:doc:</span>
103:         <span class="ruby-identifier">request</span>.<span class="ruby-identifier">remote_addr</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LOCALHOST</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">remote_ip</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LOCALHOST</span>
104:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000856" class="method-detail">
        <a name="M000856"></a>

        <div class="method-heading">
          <a href="#M000856" class="method-signature">
          <span class="method-name">log_error</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overwrite to implement custom logging of errors. By default logs as fatal.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000856-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000856-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 65</span>
65:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">log_error</span>(<span class="ruby-identifier">exception</span>) <span class="ruby-comment cmt">#:doc:</span>
66:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">silence</span> <span class="ruby-keyword kw">do</span>
67:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ActionView</span><span class="ruby-operator">::</span><span class="ruby-constant">TemplateError</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">exception</span>
68:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">fatal</span>(<span class="ruby-identifier">exception</span>.<span class="ruby-identifier">to_s</span>)
69:           <span class="ruby-keyword kw">else</span>
70:             <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">fatal</span>(
71:               <span class="ruby-node">&quot;\n\n#{exception.class} (#{exception.message}):\n    &quot;</span> <span class="ruby-operator">+</span>
72:               <span class="ruby-identifier">clean_backtrace</span>(<span class="ruby-identifier">exception</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n    &quot;</span>) <span class="ruby-operator">+</span>
73:               <span class="ruby-value str">&quot;\n\n&quot;</span>
74:             )
75:           <span class="ruby-keyword kw">end</span>
76:         <span class="ruby-keyword kw">end</span>
77:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000858" class="method-detail">
        <a name="M000858"></a>

        <div class="method-heading">
          <a href="#M000858" class="method-signature">
          <span class="method-name">render_optional_error_file</span><span class="method-args">(status_code)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attempts to render a static error page based on the <tt>status_code</tt>
thrown, or just return headers if no such file exists. For example, if a
500 error is being handled <a href="../Rails.html">Rails</a> will first
attempt to render the file at <tt>public/500.html</tt>. If the file
doesn&#8216;t exist, the body of the response will be left empty.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000858-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000858-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 89</span>
89:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render_optional_error_file</span>(<span class="ruby-identifier">status_code</span>)
90:         <span class="ruby-identifier">status</span> = <span class="ruby-identifier">interpret_status</span>(<span class="ruby-identifier">status_code</span>)
91:         <span class="ruby-identifier">path</span> = <span class="ruby-node">&quot;#{Rails.public_path}/#{status[0,3]}.html&quot;</span>
92:         <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">path</span>)
93:           <span class="ruby-identifier">render</span> <span class="ruby-identifier">:file</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">path</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">status</span>
94:         <span class="ruby-keyword kw">else</span>
95:           <span class="ruby-identifier">head</span> <span class="ruby-identifier">status</span>
96:         <span class="ruby-keyword kw">end</span>
97:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000855" class="method-detail">
        <a name="M000855"></a>

        <div class="method-heading">
          <a href="#M000855" class="method-signature">
          <span class="method-name">rescue_action</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Exception handler called when the performance of an action raises an
exception.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000855-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000855-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 60</span>
60:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rescue_action</span>(<span class="ruby-identifier">exception</span>)
61:         <span class="ruby-identifier">rescue_with_handler</span>(<span class="ruby-identifier">exception</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">rescue_action_without_handler</span>(<span class="ruby-identifier">exception</span>)
62:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000857" class="method-detail">
        <a name="M000857"></a>

        <div class="method-heading">
          <a href="#M000857" class="method-signature">
          <span class="method-name">rescue_action_in_public</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Overwrite to implement public exception handling (for requests answering
false to <tt><a href="Rescue.html#M000859">local_request?</a></tt>). By
default will call <a
href="Rescue.html#M000858">render_optional_error_file</a>. Override this
method to provide more user friendly error messages.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000857-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000857-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 81</span>
81:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rescue_action_in_public</span>(<span class="ruby-identifier">exception</span>) <span class="ruby-comment cmt">#:doc:</span>
82:         <span class="ruby-identifier">render_optional_error_file</span> <span class="ruby-identifier">response_code_for_rescue</span>(<span class="ruby-identifier">exception</span>)
83:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000860" class="method-detail">
        <a name="M000860"></a>

        <div class="method-heading">
          <a href="#M000860" class="method-signature">
          <span class="method-name">rescue_action_locally</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Render detailed diagnostics for unhandled exceptions rescued from a
controller action.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000860-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000860-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 108</span>
108:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rescue_action_locally</span>(<span class="ruby-identifier">exception</span>)
109:         <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@exception&quot;</span>, <span class="ruby-identifier">exception</span>)
110:         <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@rescues_path&quot;</span>, <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">rescues_path</span>(<span class="ruby-value str">&quot;stub&quot;</span>)))
111:         <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@contents&quot;</span>, <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">:file</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">template_path_for_local_rescue</span>(<span class="ruby-identifier">exception</span>)))
112: 
113:         <span class="ruby-identifier">response</span>.<span class="ruby-identifier">content_type</span> = <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">HTML</span>
114:         <span class="ruby-identifier">render_for_file</span>(<span class="ruby-identifier">rescues_path</span>(<span class="ruby-value str">&quot;layout&quot;</span>), <span class="ruby-identifier">response_code_for_rescue</span>(<span class="ruby-identifier">exception</span>))
115:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000861" class="method-detail">
        <a name="M000861"></a>

        <div class="method-heading">
          <a href="#M000861" class="method-signature">
          <span class="method-name">rescue_action_without_handler</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000861-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000861-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/rescue.rb, line 117</span>
117:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rescue_action_without_handler</span>(<span class="ruby-identifier">exception</span>)
118:         <span class="ruby-identifier">log_error</span>(<span class="ruby-identifier">exception</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">logger</span>
119:         <span class="ruby-identifier">erase_results</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">performed?</span>
120: 
121:         <span class="ruby-comment cmt"># Let the exception alter the response if it wants.</span>
122:         <span class="ruby-comment cmt"># For example, MethodNotAllowed sets the Allow header.</span>
123:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:handle_response!</span>)
124:           <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">handle_response!</span>(<span class="ruby-identifier">response</span>)
125:         <span class="ruby-keyword kw">end</span>
126: 
127:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">consider_all_requests_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">local_request?</span>
128:           <span class="ruby-identifier">rescue_action_locally</span>(<span class="ruby-identifier">exception</span>)
129:         <span class="ruby-keyword kw">else</span>
130:           <span class="ruby-identifier">rescue_action_in_public</span>(<span class="ruby-identifier">exception</span>)
131:         <span class="ruby-keyword kw">end</span>
132:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>